﻿using System;
using System.Collections.ObjectModel;

namespace DoVuiKinhThanh.Domain
{
    public class Quiz : DomainBase
    {
        #region Constants

        public const int CONTENT_WITHOUT_FORMAT_IN_LIST = 50;
        #endregion

        #region IFields

        private ObservableCollection<Answer> m_answers = new ObservableCollection<Answer>();
        private string m_content = string.Empty;
        private string m_contentWithoutFormat = string.Empty;
        private bool m_selected;

        #endregion

        public Quiz Clone()
        {
            var clonedQuiz = new Quiz();
            clonedQuiz.m_content = m_content;
            clonedQuiz.m_contentWithoutFormat = m_contentWithoutFormat;
            clonedQuiz.m_selected = m_selected;
            foreach (var answer in m_answers)
            {
                clonedQuiz.m_answers.Add(answer.Clone());
            }
            return clonedQuiz;
        }

        #region IProperties

        public bool Selected
        {
            get
            {
                return m_selected;
            }
            set
            {
                if (m_selected != value)
                {
                    m_selected = value;
                    OnPropertyChanged(() => Selected);
                }
            }
        }

        public ObservableCollection<Answer> Answers
        {
            get
            {
                return m_answers;
            }
            set
            {
                if (m_answers != value)
                {
                    m_answers = value;
                    OnPropertyChanged(() => Answers);
                }
            }
        }

        public string Content
        {
            get
            {
                return m_content;
            }
            set
            {
                if (m_content != value)
                {
                    m_content = value;
                    OnPropertyChanged(() => Content);
                }
            }
        }

        public string ContentWithoutFormat
        {
            get
            {
                return m_contentWithoutFormat;
            }
            set
            {
                if (m_contentWithoutFormat != value)
                {
                    m_contentWithoutFormat = value;
                    OnPropertyChanged(() => ContentWithoutFormat);
                }
            }
        }

        public string ShortenContent {
            get {
                var processedText = ContentWithoutFormat;
                if (!string.IsNullOrWhiteSpace(processedText))
                {
                    processedText = processedText.Replace(Environment.NewLine, string.Empty);
                    if (processedText.Length > CONTENT_WITHOUT_FORMAT_IN_LIST)
                    {
                        processedText = processedText.Substring(0, CONTENT_WITHOUT_FORMAT_IN_LIST) + Constants.ECLIPSE;
                    }
                }
                return processedText;
            }
        }

        #endregion
    }
}